]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dbusServices/extensions: Split error page from window
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 29 Jul 2021 22:26:05 +0000 (00:26 +0200)
committerMarge Bot <marge-bot@gnome.org>
Tue, 8 Feb 2022 19:11:19 +0000 (19:11 +0000)
The error UI comprises the bits that are actually custom. Splitting them
out from the off-the-shelf window makes it easier to replace the dialog
with libadwaita's dedicated preference window.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2012>

js/dbusServices/extensions/extensionPrefsDialog.js
js/dbusServices/extensions/ui/extension-error-page.ui [new file with mode: 0644]
js/dbusServices/extensions/ui/extension-prefs-dialog.ui [deleted file]
js/dbusServices/org.gnome.Shell.Extensions.src.gresource.xml

index f9d533a8bb9d09f69347b2dd16a67b9b648b4cfb..8fa6a533b2686d3a11a5cf0d12a6a0c859925034 100644 (file)
@@ -7,25 +7,53 @@ const ExtensionUtils = imports.misc.extensionUtils;
 
 var ExtensionPrefsDialog = GObject.registerClass({
     GTypeName: 'ExtensionPrefsDialog',
-    Template: 'resource:///org/gnome/Shell/Extensions/ui/extension-prefs-dialog.ui',
+}, class ExtensionPrefsDialog extends Gtk.Window {
+    _init(extension) {
+        super._init({
+            title: extension.metadata.name,
+            default_width: 600,
+            default_height: 400,
+        });
+        this.set_titlebar(new Gtk.HeaderBar());
+
+        try {
+            ExtensionUtils.installImporter(extension);
+
+            // give extension prefs access to their own extension object
+            ExtensionUtils.getCurrentExtension = () => extension;
+
+            const prefsModule = extension.imports.prefs;
+            prefsModule.init(extension.metadata);
+
+            const widget = prefsModule.buildPrefsWidget();
+            this.set_child(widget);
+        } catch (e) {
+            this.set_child(new ExtensionPrefsErrorPage(extension, e));
+            logError(e, 'Failed to open preferences');
+        }
+    }
+});
+
+const ExtensionPrefsErrorPage = GObject.registerClass({
+    GTypeName: 'ExtensionPrefsErrorPage',
+    Template: 'resource:///org/gnome/Shell/Extensions/ui/extension-error-page.ui',
     InternalChildren: [
-        'stack',
         'expander',
         'expanderArrow',
         'revealer',
         'errorView',
     ],
-}, class ExtensionPrefsDialog extends Gtk.Window {
-    _init(extension) {
+}, class ExtensionPrefsErrorPage extends Gtk.Widget {
+    _init(extension, error) {
         super._init({
-            title: extension.metadata.name,
+            layout_manager: new Gtk.BinLayout(),
         });
 
         this._uuid = extension.uuid;
         this._url = extension.metadata.url || '';
 
         this._actionGroup = new Gio.SimpleActionGroup();
-        this.insert_action_group('win', this._actionGroup);
+        this.insert_action_group('page', this._actionGroup);
 
         this._initActions();
         this._addCustomStylesheet();
@@ -50,61 +78,38 @@ var ExtensionPrefsDialog = GObject.registerClass({
         this._revealer.connect('notify::child-revealed',
             () => this._syncExpandedStyle());
 
-        try {
-            ExtensionUtils.installImporter(extension);
-
-            // give extension prefs access to their own extension object
-            ExtensionUtils.getCurrentExtension = () => extension;
-
-            const prefsModule = extension.imports.prefs;
-            prefsModule.init(extension.metadata);
-
-            const widget = prefsModule.buildPrefsWidget();
-            this._stack.add_named(widget, 'prefs');
-            this._stack.visible_child = widget;
-        } catch (e) {
-            this._setError(e);
-            logError(e, 'Failed to open preferences');
-        }
-    }
-
-    _syncExpandedStyle() {
-        if (this._revealer.reveal_child)
-            this._expander.add_css_class('expanded');
-        else if (!this._revealer.child_revealed)
-            this._expander.remove_css_class('expanded');
-    }
-
-    _setError(exc) {
-        this._errorView.buffer.text = `${exc}\n\nStack trace:\n`;
+        this._errorView.buffer.text = `${error}\n\nStack trace:\n`;
         // Indent stack trace.
         this._errorView.buffer.text +=
-            exc.stack.split('\n').map(line => `  ${line}`).join('\n');
+            error.stack.split('\n').map(line => `  ${line}`).join('\n');
 
         // markdown for pasting in gitlab issues
         let lines = [
             `The settings of extension ${this._uuid} had an error:`,
             '```',
-            `${exc}`,
+            `${error}`,
             '```',
             '',
             'Stack trace:',
             '```',
-            exc.stack.replace(/\n$/, ''), // stack without trailing newline
+            error.stack.replace(/\n$/, ''), // stack without trailing newline
             '```',
             '',
         ];
         this._errorMarkdown = lines.join('\n');
-        this._actionGroup.lookup('copy-error').enabled = true;
+    }
+
+    _syncExpandedStyle() {
+        if (this._revealer.reveal_child)
+            this._expander.add_css_class('expanded');
+        else if (!this._revealer.child_revealed)
+            this._expander.remove_css_class('expanded');
     }
 
     _initActions() {
         let action;
 
-        action = new Gio.SimpleAction({
-            name: 'copy-error',
-            enabled: false,
-        });
+        action = new Gio.SimpleAction({ name: 'copy-error' });
         action.connect('activate', () => {
             const clipboard = this.get_display().get_clipboard();
             clipboard.set(this._errorMarkdown);
@@ -135,4 +140,3 @@ var ExtensionPrefsDialog = GObject.registerClass({
             Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
     }
 });
-
diff --git a/js/dbusServices/extensions/ui/extension-error-page.ui b/js/dbusServices/extensions/ui/extension-error-page.ui
new file mode 100644 (file)
index 0000000..eb0a044
--- /dev/null
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="ExtensionPrefsErrorPage" parent="GtkWidget">
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="hscrollbar-policy">never</property>
+        <property name="propagate-natural-height">True</property>
+        <child>
+          <object class="GtkViewport">
+            <child>
+              <object class="GtkBox">
+                <property name="orientation">vertical</property>
+                <property name="margin-start">100</property>
+                <property name="margin-end">100</property>
+                <property name="margin-top">100</property>
+                <property name="margin-bottom">60</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="label" translatable="yes">Something’s gone wrong</property>
+                    <attributes>
+                      <attribute name="scale" value="1.44"/> <!-- x-large -->
+                    </attributes>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="label" translatable="yes">We’re very sorry, but there’s been a problem: the settings for this extension can’t be displayed. We recommend that you report the issue to the extension authors.</property>
+                    <property name="justify">center</property>
+                    <property name="wrap">True</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkFrame">
+                    <property name="margin-top">12</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="hexpand">True</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <object class="GtkBox" id="expander">
+                            <property name="spacing">6</property>
+                            <style>
+                              <class name="expander"/>
+                            </style>
+                            <child>
+                              <object class="GtkImage" id="expanderArrow">
+                                <property name="icon-name">pan-end-symbolic</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="label" translatable="yes">Technical Details</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkRevealer" id="revealer">
+                            <child>
+                              <object class="GtkBox">
+                                <property name="orientation">vertical</property>
+                                <child>
+                                  <object class="GtkTextView" id="errorView">
+                                    <property name="monospace">True</property>
+                                    <property name="editable">False</property>
+                                    <property name="wrap-mode">word</property>
+                                    <property name="left-margin">12</property>
+                                    <property name="right-margin">12</property>
+                                    <property name="top-margin">12</property>
+                                    <property name="bottom-margin">12</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkBox">
+                                    <style>
+                                      <class name="expander-toolbar"/>
+                                    </style>
+                                    <child>
+                                      <object class="GtkButton">
+                                        <property name="receives-default">True</property>
+                                        <property name="action-name">page.copy-error</property>
+                                        <property name="has-frame">False</property>
+                                        <property name="icon-name">edit-copy-symbolic</property>
+                                      </object>
+                                    </child>
+                                    <child>
+                                      <object class="GtkButton" id="homeButton">
+                                        <property name="visible"
+                                                  bind-source="homeButton"
+                                                  bind-property="sensitive"
+                                                  bind-flags="sync-create"/>
+                                        <property name="hexpand">True</property>
+                                        <property name="halign">end</property>
+                                        <property name="label" translatable="yes">Homepage</property>
+                                        <property name="tooltip-text" translatable="yes">Visit extension homepage</property>
+                                        <property name="receives-default">True</property>
+                                        <property name="has-frame">False</property>
+                                        <property name="action-name">page.show-url</property>
+                                      </object>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/js/dbusServices/extensions/ui/extension-prefs-dialog.ui b/js/dbusServices/extensions/ui/extension-prefs-dialog.ui
deleted file mode 100644 (file)
index 28f9d1b..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<interface>
-  <template class="ExtensionPrefsDialog" parent="GtkWindow">
-    <property name="default-width">600</property>
-    <property name="default-height">400</property>
-    <child type="titlebar">
-      <object class="GtkHeaderBar"/>
-    </child>
-    <child>
-      <object class="GtkStack" id="stack">
-        <child>
-          <object class="GtkScrolledWindow">
-            <property name="hscrollbar-policy">never</property>
-            <property name="propagate-natural-height">True</property>
-            <child>
-              <object class="GtkViewport">
-                <child>
-                  <object class="GtkBox">
-                    <property name="orientation">vertical</property>
-                    <property name="margin-start">100</property>
-                    <property name="margin-end">100</property>
-                    <property name="margin-top">100</property>
-                    <property name="margin-bottom">60</property>
-                    <property name="spacing">12</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">Something’s gone wrong</property>
-                        <attributes>
-                          <attribute name="scale" value="1.44"/> <!-- x-large -->
-                        </attributes>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">We’re very sorry, but there’s been a problem: the settings for this extension can’t be displayed. We recommend that you report the issue to the extension authors.</property>
-                        <property name="justify">center</property>
-                        <property name="wrap">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="margin-top">12</property>
-                        <child>
-                          <object class="GtkBox">
-                            <property name="hexpand">True</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkBox" id="expander">
-                                <property name="spacing">6</property>
-                                <style>
-                                  <class name="expander"/>
-                                </style>
-                                <child>
-                                  <object class="GtkImage" id="expanderArrow">
-                                    <property name="icon-name">pan-end-symbolic</property>
-                                  </object>
-                                </child>
-                                <child>
-                                  <object class="GtkLabel">
-                                    <property name="label" translatable="yes">Technical Details</property>
-                                  </object>
-                                </child>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkRevealer" id="revealer">
-                                <child>
-                                  <object class="GtkBox">
-                                    <property name="orientation">vertical</property>
-                                    <child>
-                                      <object class="GtkTextView" id="errorView">
-                                        <property name="monospace">True</property>
-                                        <property name="editable">False</property>
-                                        <property name="wrap-mode">word</property>
-                                        <property name="left-margin">12</property>
-                                        <property name="right-margin">12</property>
-                                        <property name="top-margin">12</property>
-                                        <property name="bottom-margin">12</property>
-                                      </object>
-                                    </child>
-                                    <child>
-                                      <object class="GtkBox">
-                                        <style>
-                                          <class name="expander-toolbar"/>
-                                        </style>
-                                        <child>
-                                          <object class="GtkButton">
-                                            <property name="receives-default">True</property>
-                                            <property name="action-name">win.copy-error</property>
-                                            <property name="has-frame">False</property>
-                                            <property name="icon-name">edit-copy-symbolic</property>
-                                          </object>
-                                        </child>
-                                        <child>
-                                          <object class="GtkButton" id="homeButton">
-                                            <property name="visible"
-                                                      bind-source="homeButton"
-                                                      bind-property="sensitive"
-                                                      bind-flags="sync-create"/>
-                                            <property name="hexpand">True</property>
-                                            <property name="halign">end</property>
-                                            <property name="label" translatable="yes">Homepage</property>
-                                            <property name="tooltip-text" translatable="yes">Visit extension homepage</property>
-                                            <property name="receives-default">True</property>
-                                            <property name="has-frame">False</property>
-                                            <property name="action-name">win.show-url</property>
-                                          </object>
-                                        </child>
-                                      </object>
-                                    </child>
-                                  </object>
-                                </child>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
-  </template>
-</interface>
index bca8c75ecb0f691042dc8348cbd1ed7ca96abcab..c3b81cfc21e6ce090f12d974e8fc4ae5885f99fe 100644 (file)
@@ -14,6 +14,6 @@
 
   <gresource prefix="/org/gnome/Shell/Extensions">
     <file>css/application.css</file>
-    <file>ui/extension-prefs-dialog.ui</file>
+    <file>ui/extension-error-page.ui</file>
   </gresource>
 </gresources>